package acl.hibernate.dao;


import java.util.List;

import acl.hibernate.po.OaUsers;
import hibernate.HibernateBaseDAO;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class Userdao extends HibernateBaseDAO{
	// 实例化一个session工厂	
	public List getUserByName(String userName)
	{
		List result=null;
		String hql=" from OaUsers as o where o.username='"+userName+"'";
		result=this.find(hql);
		return result;
	}
	public  List searchUsersByKeys(String keys) {
		//根据条件查询用户信息
		// Author:Never		
		List result = null;
		Query query = null;
		session=this.getSession();
		String hql = "from UserView as uv where 1=1 and uv.userstate =1 ";
		if(!keys.equals("")){
			String[] key = keys.split(" ");
			for(int i = 0;i<key.length;i++){
				String n = (key[i]).trim();
				hql+="and uv.allContent like '%"+n+"%' ";
			}
		}
		query = session.createQuery(hql);
		try {
			result = query.list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally{			
			this.closeSession(session);
		}
		return result;
	}
	public  List searchUsersByKeys(String keys,String pageno,String pagesize) {
		//根据条件查询用户信息
		// Author:Never		
		HibernateBaseDAO dao=new HibernateBaseDAO();
		List result = null;
		Query query = null;
		session=this.getSession();
		String hql = "from UserView as uv where 1=1 and uv.userstate =1 ";
		if(!"".equals(keys)){
			String[] key = keys.split(" ");
			for(int i = 0;i<key.length;i++){
				String n = (key[i]).trim();
				hql+="and uv.allContent like '%"+n+"%' ";
			}
		}
		try {
			result = dao.query(Integer.parseInt(pageno), Integer.parseInt(pagesize), hql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally{			
			this.closeSession(session);
		}
		return result;
	}
	public List getPersonViewList(String keys)
	{
		List result=null;
		Query query = null;
		session=this.getSession();
		String hql = "from PersonView as uv where 1=1 and uv.id.allcontent like'%"+keys+"%'";
		
		try {
			result = this.find(hql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally{			
			this.closeSession(session);
		}
		return result;
	}
}
